package com.second.rbm;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/4/27 10:40 上午
 */

import com.rabbitmq.client.Channel;
import com.second.service.IFOrdService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import com.second.consts.RabbitConst;


import java.io.IOException;
import java.util.Map;

@Component
public class OrdRbmDeadService {

    @Autowired
    private IFOrdService ordService;

    //处理超时的订单
    @RabbitHandler
    @RabbitListener(queues = RabbitConst.ORD_DEAD_QUEUE)
    public void handlerTimeOrder(Map<String, Object> args, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) Long tag) throws IOException {
        System.out.println("死信队列..开始处理超时的这些订单~~~");

        //获取订单的id/实际业务中的订单编号
        String ordNo = (String) args.get("ordNo");

        ordService.outTimeOrd(ordNo);//将未支付的订单状态设置状态为过期

        //手动删除
        channel.basicAck(tag, false);

    }
}
